package quick.frame.service.contract.presenter;

import android.support.annotation.NonNull;

import java.util.List;

import io.reactivex.functions.Consumer;
import okhttp3.Cache;
import quick.frame.service.bean.WareHouse;
import quick.frame.service.contract.ReceiveContract;
import quick.frame.service.contract.model.ReceiveModel;

public class ReceivePresenterImpl extends ReceiveContract.ReceivePresenter {

    @NonNull
    public static ReceivePresenterImpl newInstance() {
        return new ReceivePresenterImpl();
    }
    @Override
    protected ReceiveContract.IReceiveModel getModel() {
        return ReceiveModel.newInstance();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void loadWareHourseList() {
        if (mIModel == null || mIView == null)
            return;

        mRxManager.register(mIModel.getWareHouseList().subscribe(new Consumer<List<WareHouse>>() {
            @Override
            public void accept(List<WareHouse> wareHouses) throws Exception {
                if (mIView == null)
                    return;

                mIView.updateContentList(wareHouses);
                //Cache.saveHotMovieCache(hotMovieBean.getSubjects());
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                if (mIView != null) {
                    if (mIView.isVisiable())
                        mIView.showToast("Network error.");

//                    if (Cache.getHotMovieCache().size() == 0) {//没有缓存缓存，显示网络错误界面
//                        mIView.showNetworkError();
//                    } else {
//                        mIView.updateContentList(Cache.getHotMovieCache());//加载缓存
//                    }
                }
            }
        }));
    }
}
